<html>
<head><meta charset="utf-8"><title>rustc_middle mac os x weirdness · t-compiler/shrinkmem-sprint · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/276895-t-compiler/shrinkmem-sprint/index.html">t-compiler/shrinkmem-sprint</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/276895-t-compiler/shrinkmem-sprint/topic/rustc_middle.20mac.20os.20x.20weirdness.html">rustc_middle mac os x weirdness</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="227333210"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/276895-t-compiler/shrinkmem-sprint/topic/rustc_middle%20mac%20os%20x%20weirdness/near/227333210" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/276895-t-compiler/shrinkmem-sprint/topic/rustc_middle.20mac.20os.20x.20weirdness.html#227333210">(Feb 22 2021 at 20:36)</a>:</h4>
<p>While experimenting with reporting <code>maxrss</code> acquired via <code>getrusage</code>, I have found something odd</p>



<a name="227333292"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/276895-t-compiler/shrinkmem-sprint/topic/rustc_middle%20mac%20os%20x%20weirdness/near/227333292" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/276895-t-compiler/shrinkmem-sprint/topic/rustc_middle.20mac.20os.20x.20weirdness.html#227333292">(Feb 22 2021 at 20:37)</a>:</h4>
<p>I’m still trying to confirm this, but it seems like on my mac, I am consistently observing rustc_middle taking about 2.5 GB maxrss</p>



<a name="227333547"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/276895-t-compiler/shrinkmem-sprint/topic/rustc_middle%20mac%20os%20x%20weirdness/near/227333547" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/276895-t-compiler/shrinkmem-sprint/topic/rustc_middle.20mac.20os.20x.20weirdness.html#227333547">(Feb 22 2021 at 20:39)</a>:</h4>
<p>is that lower or higher than you expect?</p>



<a name="227333693"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/276895-t-compiler/shrinkmem-sprint/topic/rustc_middle%20mac%20os%20x%20weirdness/near/227333693" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/276895-t-compiler/shrinkmem-sprint/topic/rustc_middle.20mac.20os.20x.20weirdness.html#227333693">(Feb 22 2021 at 20:40)</a>:</h4>
<p>lower</p>



<a name="227333714"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/276895-t-compiler/shrinkmem-sprint/topic/rustc_middle%20mac%20os%20x%20weirdness/near/227333714" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/276895-t-compiler/shrinkmem-sprint/topic/rustc_middle.20mac.20os.20x.20weirdness.html#227333714">(Feb 22 2021 at 20:40)</a>:</h4>
<p>let me go check what i was seeing on linux</p>



<a name="227333722"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/276895-t-compiler/shrinkmem-sprint/topic/rustc_middle%20mac%20os%20x%20weirdness/near/227333722" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/276895-t-compiler/shrinkmem-sprint/topic/rustc_middle.20mac.20os.20x.20weirdness.html#227333722">(Feb 22 2021 at 20:40)</a>:</h4>
<p>but I thought on Linux it was on the order of 6 GB</p>



<a name="227333996"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/276895-t-compiler/shrinkmem-sprint/topic/rustc_middle%20mac%20os%20x%20weirdness/near/227333996" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tm <a href="https://rust-lang.github.io/zulip_archive/stream/276895-t-compiler/shrinkmem-sprint/topic/rustc_middle.20mac.20os.20x.20weirdness.html#227333996">(Feb 22 2021 at 20:42)</a>:</h4>
<p>it could be a consequence of <a href="https://github.com/rust-lang/rust/issues/70951">#70951</a> :-).</p>



<a name="227334376"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/276895-t-compiler/shrinkmem-sprint/topic/rustc_middle%20mac%20os%20x%20weirdness/near/227334376" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/276895-t-compiler/shrinkmem-sprint/topic/rustc_middle.20mac.20os.20x.20weirdness.html#227334376">(Feb 22 2021 at 20:46)</a>:</h4>
<p>oh, you’re right; I wasn’t checking if I was comparing the same builds</p>



<a name="227335704"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/276895-t-compiler/shrinkmem-sprint/topic/rustc_middle%20mac%20os%20x%20weirdness/near/227335704" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/276895-t-compiler/shrinkmem-sprint/topic/rustc_middle.20mac.20os.20x.20weirdness.html#227335704">(Feb 22 2021 at 20:55)</a>:</h4>
<p>(but, no; I think both of the builds I’m evaluated are at the same point in the git history, and both predate PR <a href="https://github.com/rust-lang/rust/issues/70951">#70951</a> landing. I think. Checking again now.)</p>



<a name="227342074"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/276895-t-compiler/shrinkmem-sprint/topic/rustc_middle%20mac%20os%20x%20weirdness/near/227342074" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tyson Nottingham <a href="https://rust-lang.github.io/zulip_archive/stream/276895-t-compiler/shrinkmem-sprint/topic/rustc_middle.20mac.20os.20x.20weirdness.html#227342074">(Feb 22 2021 at 21:40)</a>:</h4>
<p>The memory usage is going to depend on the number of CPUs on the system, so if they're different, that could account for it. Also, the allocators will behave differently.</p>
<p>Btw, I found that changes over the last ~8 days have reduced max-RSS when compiling the entire rustc by around 750 MB on my 8 CPU system. I'm sure <a href="https://github.com/rust-lang/rust/issues/70951">#70951</a> accounts for all or most of that.</p>



<a name="227343322"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/276895-t-compiler/shrinkmem-sprint/topic/rustc_middle%20mac%20os%20x%20weirdness/near/227343322" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/276895-t-compiler/shrinkmem-sprint/topic/rustc_middle.20mac.20os.20x.20weirdness.html#227343322">(Feb 22 2021 at 21:49)</a>:</h4>
<p><span class="user-mention silent" data-user-id="306073">Tyson Nottingham</span> <a href="#narrow/stream/276895-t-compiler.2Fshrinkmem-sprint/topic/rustc_middle.20mac.20os.20x.20weirdness/near/227342074">said</a>:</p>
<blockquote>
<p>The memory usage is going to depend on the number of CPUs on the system, so if they're different, that could account for it.</p>
</blockquote>
<p>is this true even if I pass <code>-j1</code> to <code>x.py</code>, or will passing that act as a control for that variable?</p>



<a name="227343663"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/276895-t-compiler/shrinkmem-sprint/topic/rustc_middle%20mac%20os%20x%20weirdness/near/227343663" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tyson Nottingham <a href="https://rust-lang.github.io/zulip_archive/stream/276895-t-compiler/shrinkmem-sprint/topic/rustc_middle.20mac.20os.20x.20weirdness.html#227343663">(Feb 22 2021 at 21:51)</a>:</h4>
<p>It's true even with -j1, at least until <a href="https://github.com/rust-lang/rust/issues/82127">#82127</a> is in the bootstrapping compiler.</p>



<a name="227343750"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/276895-t-compiler/shrinkmem-sprint/topic/rustc_middle%20mac%20os%20x%20weirdness/near/227343750" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/276895-t-compiler/shrinkmem-sprint/topic/rustc_middle.20mac.20os.20x.20weirdness.html#227343750">(Feb 22 2021 at 21:52)</a>:</h4>
<p>I'm not sure about default allocators, but I recall that eddyb ran into a jemalloc behavior where there's a background thread that every 30 seconds cleans up memory or something like that, which meant that if your benchmark was ~30 seconds long (under or over depending on noise easily) you could see massively different instruction counts. I imagine it'd have similar effects on memory.</p>



<a name="227343846"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/276895-t-compiler/shrinkmem-sprint/topic/rustc_middle%20mac%20os%20x%20weirdness/near/227343846" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/276895-t-compiler/shrinkmem-sprint/topic/rustc_middle.20mac.20os.20x.20weirdness.html#227343846">(Feb 22 2021 at 21:53)</a>:</h4>
<p><span class="user-mention silent" data-user-id="306073">Tyson Nottingham</span> <a href="#narrow/stream/276895-t-compiler.2Fshrinkmem-sprint/topic/rustc_middle.20mac.20os.20x.20weirdness/near/227343663">said</a>:</p>
<blockquote>
<p>It's true even with -j1, at least until <a href="https://github.com/rust-lang/rust/issues/82127">#82127</a> is in the bootstrapping compiler.</p>
</blockquote>
<p>I find this surprising -- I would expect -j1 to isolate you to one CPU (aside from allocator shenanigans like the one I mention), so the <em>number</em> of CPUs shouldn't matter</p>



<a name="227343904"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/276895-t-compiler/shrinkmem-sprint/topic/rustc_middle%20mac%20os%20x%20weirdness/near/227343904" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/276895-t-compiler/shrinkmem-sprint/topic/rustc_middle.20mac.20os.20x.20weirdness.html#227343904">(Feb 22 2021 at 21:53)</a>:</h4>
<p>comparing macOS's default allocator to glibc though seems like it's going to have different behavior though no matter what</p>



<a name="227343927"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/276895-t-compiler/shrinkmem-sprint/topic/rustc_middle%20mac%20os%20x%20weirdness/near/227343927" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/276895-t-compiler/shrinkmem-sprint/topic/rustc_middle.20mac.20os.20x.20weirdness.html#227343927">(Feb 22 2021 at 21:53)</a>:</h4>
<p>(or to jemalloc)</p>



<a name="227344009"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/276895-t-compiler/shrinkmem-sprint/topic/rustc_middle%20mac%20os%20x%20weirdness/near/227344009" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/276895-t-compiler/shrinkmem-sprint/topic/rustc_middle.20mac.20os.20x.20weirdness.html#227344009">(Feb 22 2021 at 21:54)</a>:</h4>
<p>different behavior, I totally expect. but going from 2.5 GB to 6 GB is more extreme than I would have expected.</p>



<a name="227344059"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/276895-t-compiler/shrinkmem-sprint/topic/rustc_middle%20mac%20os%20x%20weirdness/near/227344059" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/276895-t-compiler/shrinkmem-sprint/topic/rustc_middle.20mac.20os.20x.20weirdness.html#227344059">(Feb 22 2021 at 21:54)</a>:</h4>
<p>(Caveat: I still need to verify this. I’m doing something else at moment but hoping to come back to this in a sec.)</p>



<a name="227344601"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/276895-t-compiler/shrinkmem-sprint/topic/rustc_middle%20mac%20os%20x%20weirdness/near/227344601" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tyson Nottingham <a href="https://rust-lang.github.io/zulip_archive/stream/276895-t-compiler/shrinkmem-sprint/topic/rustc_middle.20mac.20os.20x.20weirdness.html#227344601">(Feb 22 2021 at 21:58)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116122">simulacrum</span> <a href="#narrow/stream/276895-t-compiler.2Fshrinkmem-sprint/topic/rustc_middle.20mac.20os.20x.20weirdness/near/227343846">said</a>:</p>
<blockquote>
<p>I find this surprising -- I would expect -j1 to isolate you to one CPU (aside from allocator shenanigans like the one I mention), so the <em>number</em> of CPUs shouldn't matter</p>
</blockquote>
<p>It does isolate you to one CPU, but the problem is that the codegen scheduler still thinks we need to codegen a bunch of CGUs to LLVM modules ahead of time in order to meet demand of number-of-CPUs workers, basically. So it has more LLVM modules in memory at once than it needs to with -j1. That's one of the things that <a href="https://github.com/rust-lang/rust/issues/82127">#82127</a> resolves.</p>



<a name="227344702"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/276895-t-compiler/shrinkmem-sprint/topic/rustc_middle%20mac%20os%20x%20weirdness/near/227344702" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/276895-t-compiler/shrinkmem-sprint/topic/rustc_middle.20mac.20os.20x.20weirdness.html#227344702">(Feb 22 2021 at 21:59)</a>:</h4>
<p>Ah, right, and since we use time as a metric for how to schedule, that can definitely vary between cpus</p>



<a name="227346691"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/276895-t-compiler/shrinkmem-sprint/topic/rustc_middle%20mac%20os%20x%20weirdness/near/227346691" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/276895-t-compiler/shrinkmem-sprint/topic/rustc_middle.20mac.20os.20x.20weirdness.html#227346691">(Feb 22 2021 at 22:06)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116083">pnkfelix</span> <a href="#narrow/stream/276895-t-compiler.2Fshrinkmem-sprint/topic/rustc_middle.20mac.20os.20x.20weirdness/near/227344059">said</a>:</p>
<blockquote>
<p>(Caveat: I still need to verify this. I’m doing something else at moment but hoping to come back to this in a sec.)</p>
</blockquote>
<p>hmm, apparently what I rememered as 6 GB on Linux is actually 3.4 GB … so, not as severe as what I had thought… <span aria-label="shrug" class="emoji emoji-1f937" role="img" title="shrug">:shrug:</span></p>



<a name="227347707"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/276895-t-compiler/shrinkmem-sprint/topic/rustc_middle%20mac%20os%20x%20weirdness/near/227347707" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/276895-t-compiler/shrinkmem-sprint/topic/rustc_middle.20mac.20os.20x.20weirdness.html#227347707">(Feb 22 2021 at 22:11)</a>:</h4>
<p>(argh wait let me try again with a clean build… What’s wrong with me…)</p>



<a name="227452221"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/276895-t-compiler/shrinkmem-sprint/topic/rustc_middle%20mac%20os%20x%20weirdness/near/227452221" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/276895-t-compiler/shrinkmem-sprint/topic/rustc_middle.20mac.20os.20x.20weirdness.html#227452221">(Feb 23 2021 at 15:52)</a>:</h4>
<p><del>hmm. So some of my clean Linux runs yielded maxrss 3.4 GB for rustc_middle, but one I just did now (starting from the same point) yielded 7.2 GB.</del> Argh! I forgot, this more recent run wasn’t passing <code>-j1</code>! Passing <code>-j1</code> brings it back down to 3.4 GB</p>



<a name="227452267"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/276895-t-compiler/shrinkmem-sprint/topic/rustc_middle%20mac%20os%20x%20weirdness/near/227452267" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/276895-t-compiler/shrinkmem-sprint/topic/rustc_middle.20mac.20os.20x.20weirdness.html#227452267">(Feb 23 2021 at 15:52)</a>:</h4>
<p><del>so that’s not great, in terms of trying to rely on this data</del></p>



<a name="227452349"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/276895-t-compiler/shrinkmem-sprint/topic/rustc_middle%20mac%20os%20x%20weirdness/near/227452349" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/276895-t-compiler/shrinkmem-sprint/topic/rustc_middle.20mac.20os.20x.20weirdness.html#227452349">(Feb 23 2021 at 15:53)</a>:</h4>
<p>I suppose a natural next step would be to use a different tool to try to determine what the truth is</p>



<a name="227452446"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/276895-t-compiler/shrinkmem-sprint/topic/rustc_middle%20mac%20os%20x%20weirdness/near/227452446" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/276895-t-compiler/shrinkmem-sprint/topic/rustc_middle.20mac.20os.20x.20weirdness.html#227452446">(Feb 23 2021 at 15:53)</a>:</h4>
<p>but I’m also wondering: Do I attempt to land this code at this point? The main data I want to get from it is the maxrss reading, but I am now worried that the values are too noisy to be of real use. (Update: less worried after remembered the <code>-j1</code> issue. Looking into it more…)</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>